package priv.demos.demo1.solution.main;


import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

/**
 * Created on 2017/1/11.
 */
public class Main5 {

    public static void main(String[] args) throws Exception {
        String fileName = "D:/tmp/tmp1";
        String zipName = "D:/tmp/tmp_1.zip";
        BufferedInputStream is = new BufferedInputStream(new FileInputStream(new File(fileName)));
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        FileOutputStream fos = new FileOutputStream(zipName);
        ZipOutputStream zos = new ZipOutputStream(buffer);
        zos.putNextEntry(new ZipEntry("content"));
        BufferedOutputStream os = new BufferedOutputStream(zos);
        byte[] ary = new byte[1024];
        while (true) {
            int i = is.read(ary);
            System.out.println("i = " + i);
            if (i < 0) {
                break;
            }
            os.write(ary,0,i);
        }
        is.close();
        os.close();


        String s = buffer.toString();
        System.out.println("s = " + s);

        ByteArrayInputStream iis = new ByteArrayInputStream(buffer.toByteArray());
        ZipInputStream zis = new ZipInputStream(iis);
        zis.getNextEntry();
        ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();

        while (true) {
            int i = zis.read(ary);
            System.out.println("i = " + i);
            if (i < 0) {
                break;
            }
            outBuffer.write(ary,0,i);
        }
        outBuffer.close();
        System.out.println(outBuffer.toString());

    }
}